//
//  HWSaveMoneyCardTopCell.swift
//  HWanGame
//
//  Created by 王昌健 on 2022/6/29.
//  Copyright © 2022 94hwan. All rights reserved.
//

import UIKit

class HWSaveMoneyCardTopCell: UITableViewCell {
    var bgImageView:UIImageView!
    var lineBgImageView:UIImageView!
    var topLabel:UILabel!
    var model:HWSaveModeyCardModel? {
        didSet {
            if model?.is_buy == "1" {
                topLabel.text = "剩余 \(model?.shengyu_day ?? "")天到期"
            }else if model?.is_buy == "2" {
                topLabel.text = "剩余 \(model?.shengyu_day ?? "")天到期"
            } else {
                topLabel.text = "开通超级省钱卡"
            }
        }
    }
    class func cellWithTableView(tableView:UITableView) -> (HWSaveMoneyCardTopCell) {
        let reUse:String = "HWSaveMoneyCardTopCell"
        
        var cell = tableView.dequeueReusableCell(withIdentifier: reUse)
        
        if cell == nil {
            cell = HWSaveMoneyCardTopCell.init(style: UITableViewCell.CellStyle.default, reuseIdentifier: reUse)
        }
        
        return cell as! HWSaveMoneyCardTopCell
    }
    
    
    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        
        initUI()
        initFrame()
    }
    
    func initUI() -> Void {
        selectionStyle = UITableViewCell.SelectionStyle.none
        backgroundColor = UIColor.clear
        
        bgImageView = UIImageView()
        bgImageView.image = UIImage(named: "superSaveMoney")
        contentView.addSubview(bgImageView)
        
        lineBgImageView = UIImageView()
        lineBgImageView.image = UIImage(named: "saveMoneyLine")
        contentView.addSubview(lineBgImageView)
        
        contentView.layer.masksToBounds = true
        
        topLabel = HWLabel.createLabel(title: "开通超级省钱卡", color: "#EAD9BD", font: 11*widthScale)
        topLabel.layer.cornerRadius = 8*widthScale
        topLabel.layer.borderColor = UIColor.colorWithHexString(hexString: "#EAD9BD").cgColor
        topLabel.textAlignment = .center
        topLabel.layer.borderWidth = 1
        bgImageView.addSubview(topLabel)
    }
    
    func initFrame() -> Void {
        bgImageView.snp.makeConstraints { make in
            make.left.equalTo(7*widthScale)
            make.right.equalTo(-7*widthScale)
            make.top.equalTo(7*widthScale)
            make.height.equalTo(203*widthScale)
        }
        
        lineBgImageView.snp.makeConstraints { make in
            make.left.right.bottom.equalToSuperview().priority(.high)
            make.top.equalTo(147*widthScale)
            make.height.equalTo(37*widthScale)
        }
        
        topLabel.snp.makeConstraints { make in
            make.right.equalTo(-37*widthScale)
            make.top.equalTo(43*widthScale)
            make.width.equalTo(85*widthScale)
            make.height.equalTo(16*widthScale)
        }
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
    }
    
    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)
        
        // Configure the view for the selected state
    }
    
}
